<template>
  <el-container>
    <!--查询条件开始-->
    <el-header height="1">
      <el-form ref="queryForm" size="small" :model="parmsValue.query" label-width="160px" class="middle-form">
        <el-row>
          <el-col :span="8">
            <el-form-item prop="fee_adtype" label="费用分类">
              <el-select v-model="parmsValue.query.fee_adtype" :clearable="true">
                <el-option v-for="(item,index) in dict.fee_adtype" :key="index" :value="index" :label="item" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="fset_name" label="费用方案名称">
              <el-input v-model="parmsValue.query.fset_name" :clearable="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-button type="success" size="small" @click="query">查询</el-button>
          <el-button type="info" size="small" @click="resetFields('queryForm')">重置</el-button>
          <el-button type="success" size="small" @click="showPage('add')">新增</el-button>
        </el-row>
      </el-form>
    </el-header>
    <!--查询条件结束-->
    <!--列表开始-->
    <el-main>
      <table-pagination
        :table-data="table.feeSet.tableData"
        :table-header-config="table.tableHeaderConfig"
        :total="table.feeSet.total"
        :dict-data="dict"
        :page-size="table.feeSet.limit"
        :now-page="table.feeSet.nowPage"
        :operation-config="table.operationConfig"
        @current-change="currentChange"
      />
    </el-main>
    <!--列表结束-->
  </el-container>
</template>

<script>
  import { formItems } from '@/utils/formItems'
  import * as kk from '@/utils/k-utils'
  import request from '@/utils/request'
  import axios from 'axios'

  export default {
    data() {
      return {
        dict: { fee_adtype: {}},
        table: {
          feeSet: {
            tableData: [],
            exeid: 'M8FeeManage003',
            total: 100,
            limit: 10,
            nowPage: 1
          },
          tableHeaderConfig: [
            { prop: 'fee_adtype', label: '费用分类' },
            { prop: 'plan_code', label: '费用方案代码' },
            { prop: 'plan_name', label: '方案名称' },
            { prop: 'note', label: '备注' }
          ],
          operationConfig: {
            fixed: 'left',
            width: 220,
            operationButton: [
              { value: '修改', func: params => this.showPage('update', params) },
              { value: '删除', func: params => this.deleteSchema(params) },
              { value: '详情', func: params => this.showPage('detail', params) }
            ]
          }
        },
        parmsValue: {
          // 查询字段值
          query: {
            fee_adtype: '',
            fset_name: ''
          }
        }
      }
    },
    // 生命周期开始
    beforeMount() {
      this.init()
    },
    // 生命周期结束
    methods: {
      showPage(editMode, params) {
        switch (editMode) {
        case 'add':
          this.$router.push({ path: '/feeManage_add' })
          break
        case 'update':
          this.$router.push({ path: '/feeManage_update', query: params })
          break
        case 'detail':
        default:
          this.$router.push({ path: '/feeManage_detail', query: params })
        }
      },
      query() {
        this.table.feeSet.nowPage = 1
        this.loadTable()
      },
      init() {
        const dictReq = []
        const dicts = ['t8_fee_adtype']
        dicts.forEach(key => dictReq.push(request({
          url: 'system/base/dict/' + key + '.json',
          method: 'post',
          loading: true
        })))
        axios.all(dictReq).then(axios.spread((fee_adtype) => {
          this.dict['fee_adtype'] = fee_adtype
          this.loadTable()
        }))
      },
      currentChange(index) {
        this.table.feeSet.nowPage = index
        this.loadTable()
      },
      loadTable() {
        this.table.feeSet.fee_adtype = this.parmsValue.query.fee_adtype
        this.table.feeSet.fset_name = this.parmsValue.query.fset_name
        kk.k_load_table(this, 'feeSet', formItems.FEE)
      },
      resetFields(form) {
        this.$refs[form].resetFields()
      },
      deleteSchema(params) {
        this.$confirm('确认删除费用方案吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          kk.k_update_exeid(formItems.FEE, 'M8FeePlanEQ004', params).then(resp => {
            if (resp.success) {
              this.loadTable()
            }
          })
        }).catch(() => {
        })
      }
    }
  }
</script>
